{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<style>
    .layui-laydate-header {
        display: none;
    }

    .layui-laydate-content > table > thead {
        display: none;
    }

    .laydate-day-prev {
        display: none;
    }

    .laydate-day-next {
        display: none;
    }

    .pl_btn {
        color: #4c9cfb !important;
        cursor: pointer;
    }
</style>
<form class="layui-form p-4">
    <h3 class="pb-3">功能菜单/节点</h3>
    <table class="layui-table layui-table-form">
        <tr>
            <td>{$pType>2?'供应商':'客户'}</td>
          <td>
            <select name="punterId"  id="punterId" lay-search lay-filter="punterId">
                <option value="">请选择</option>
                {volist name="punterList" id="pl"}
                <option value="{$pl.id}" >{$pl.name}</option>
                {/volist}
            </select>
        </td>
        </tr>
        {if $pType=='1'}
        <tr>

            <td class="layui-td-gray">收货人
            </td>
            <td>
                <select name="saveId" id="saveId" lay-search lay-filter="saveId">
                    <option value="">请选择</option>
                </select>
            </td>
            <td class="layui-td-gray-2">收货人电话

            </td>
            <td> <input type="text" name="savePhone" value="{$detail.savePhone|default=''}" lay-verify="required" readonly class="layui-input layui-disabled" placeholder="选择收货人">
                <input type="hidden" name="saveName" value="{$detail.saveName|default=''}">
            </td>
            <td class="layui-td-gray-2">收货人地址
            </td>
            <td>
                <input type="text" name="saveAdd" value="{$detail.saveAdd|default=''}" lay-verify="required" readonly class="layui-input layui-disabled" placeholder="选择收货人">

            </td>
        </tr>
        {/if}
{if $pType=='1'}
        <tr>
            <td class="layui-td-gray-2">快递公司
            </td>
            <td>
                <input type="text" name="kdCompany" value=""
                       autocomplete="off" placeholder="请输入"
                       class="layui-input ">
            </td>
            <td class="layui-td-gray-2">快递单号
            </td>
            <td>
                <input type="text" name="kdOrderNum" value=""
                       autocomplete="off" placeholder="请输入"
                       class="layui-input ">
            </td>
        </tr>
{/if}
        <tr>
            <td colspan="6"><h4>明细</h4></td>
        </tr>
        <tr>

            <td colspan="6">

                <table class="layui-table tableMany">
                    <thead>
                    <tr>
                        <td>序号</td>
                        <td>物料编码</td>
                        <td>品牌</td>
                        <td>品名</td>
                        <td>型号</td>
                        <td>订货号</td>
                        <td>计量单位</td>
                        <td>仓库</td>
                        <td>数量</td>
                    </tr>
                    </thead>
                    <tbody id="mxTbdy">
                    {volist name="list" id="ml" key='k'}
                    <tr>
                        <td>
                            <span class="xuhao">{$k}</span>
                            <input type="hidden" name="mx[saleContractOrder][]" value="{$ml.orderNum}">
                            <input type="hidden" name="mx[mxid][]" value="{$ml.id}">
                            <input type="hidden" class="mx_mdId" name="mx[mdId][]" value="{$ml.mdId}">
                        </td>
                        <td>{$ml.bar_code}</td>
                        <td>{$ml.brand}</td>
                        <td>{$ml.mdName}</td>
                        <td>{$ml.specs}</td>
                        <td>{$ml.buyCode}</td>
                        <td>{$ml.unit}</td>
                        <td>
                            <select name="mx[wId][]" >
                                {volist name="warehouse" id="wl"}
                                <option value="{$wl.id}" >{$wl.name}</option>
                                {/volist}
                            </select>
                        </td>
                      <td><input type="text" name="mx[num][]" value="{$ml.bjNum}" class="layui-input num"
                                   lay-verify="required" oninput="digitalFiltering(this,2)"></td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>

            </td>
        </tr>
    </table>
    <div class="py-3">
        <input type="hidden" name="ids" value="{$ids}">
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">保存</button>
    </div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool'];

    function gouguInit() {
        var form = layui.form, tool = layui.tool, level = 0, laydate = layui.laydate;
        //监听提交
        form.on('submit(webform)', function (data) {
            let callback = function (e) {
                layer.msg(e.msg);
                if (e.code == 0) {
                    setTimeout(function () {
                        parent.parent.location.reload();
                    }, 1000);
                }
            }
            tool.post("{:url('')}", data.field, callback);
            return false;
        });
        form.on('select(punterId)', function (data) {
            console.log('data',data)
            getPunterMember(data.value);
        });

        form.on('select(saveId)', function (data) {
            let value=data.value;
            if (data.value==''){
                $("input[name ='saveName']").val();
                $("input[name ='savePhone']").val();
                $("input[name ='saveAdd']").val();
            }else {
                saveList.forEach(function (item) {
                    if (item.id==value){
                        $("input[name ='saveName']").val(item.name);
                        $("input[name ='savePhone']").val(item.phone);
                        $("input[name ='saveAdd']").val(item.address);
                        return;
                    }
                })
            }
        });
    }
    function getPunterMember(punterId='') {
        $("#contactId").empty();
        $("#saveId").empty();
        $("input[name ='contactName']").val();
        $("input[name ='contactPhone']").val();
        $("input[name ='saveName']").val();
        $("input[name ='savePhone']").val();
        $("input[name ='saveAdd']").val();
        contactList=[];
        saveList=[];
        if (punterId==''){
            layui.form.render();
            return;
        }
        httpRequest("{:url('api/getPurveyorMember')}",{purveyorId:punterId},function (res) {
            if (res.code==0){
                contactList=res.data.contactList;
                saveList=res.data.saverList;
                let contactStr='  <option value="">请选择</option>';
                let saverStr='  <option value="">请选择</option>';
                let contactId="{$detail.contactId|default='0'}"
                let saveId="{$detail.saveId|default='0'}"
                contactList.forEach(function (item) {
                    let cStr='';
                    if (item.id==contactId){
                        cStr='selected';
                    }
                    contactStr+='  <option value="'+item.id+'" '+cStr+'>'+item.name+'</option>'
                })
                saveList.forEach(function (item) {
                    let s_Str='';
                    if (item.id==saveId){
                        s_Str='selected';
                    }
                    saverStr+='  <option value="'+item.id+'" '+s_Str+'>'+item.name+'</option>'
                })
                console.log(saverStr)
                $("#contactId").append(contactStr);
                $("#saveId").append(saverStr);
                layui.form.render();
            }else {

            }
        },false)
    }

</script>
{/block}
<!-- /脚本 -->